import { Base64 } from 'js-base64';

/**
 * Checks if the input object is null or undefined.
 * @param input The input object.
 * @return The boolean result. True means the input is null or undefined. False means NOT.
 */
export function isNullOrUndefined(input: any): boolean {
  return input === null || input === undefined;
}

/**
 * Checks if the input string is null, undefined or empty string.
 * @param input The input string.
 * @return The boolean result. True means the input is null, undefined or empty string. False means NOT.
 */
export function isNullOrUndefinedOrEmptyString(input: any): boolean {
  return isNullOrUndefined(input) || input === '';
}

/**
 * Checks the input to see if its type is string and the value is not empty.
 * @param input The input instance will be checked.
 * @return True means the input is string type and it is not empty.
 */
export function isNotEmptyString(input: any): boolean {
  return typeof input === 'string' && input !== '';
}

/**
 * Encodes the string to base64 format.
 * @param rawString The raw string value will be converted to base64 format.
 * @returns The encoded string value.
 */
export function encodeToBase64String(rawString: string): string {
  return Base64.encode(rawString);
}

/**
 * Decodes the string from base64 format.
 * @param encodedString The encoded base64 format string value.
 * @returns The decoded string value.
 */
export function decodeFromBase64String(encodedString: string): string {
  return Base64.decode(encodedString);
}
